package com.gnerv.sylvanas.module.mybatis.extend;

import lombok.Data;
import org.springframework.util.StringUtils;

@Data
public class DtoExtendResult {

    private static final String EXTEND_DTO = "ExtendDTO";

    private Class<?> main;
    private Class<?> extend;
    private String method;
    private String column;
    private String key;

    public DtoExtendResult(Class<?> main, Class<?> extend, String method, String column, String key) {
        this.main = main;
        this.extend = extend;
        this.method = method;
        this.column = column;
        this.key = key;
    }

    public String key(){
        if(StringUtils.hasText(this.key)){
            return this.key;
        }
        char[] charArray = this.main.getSimpleName().toCharArray();
        charArray[0] = Character.toLowerCase(charArray[0]);
        return String.valueOf(charArray);
    }

    public String column(){
        return column.replace("{", "").replace("}", "");
    }

    public String resultType(){
        return extend.getName();
    }

    public String resultMapId(){
        return main.getName() + EXTEND_DTO;
    }
}
